from appium import webdriver

from appium0704.appiumpo.BasePage import BasePage
from appium0704.appiumpo.MainPage import MainPage


class App(BasePage):
    def start(self):
        if self.driver == None:
            caps = {}
            caps["platformName"] = "Android"
            caps["appPackage"] = "com.tencent.wework"
            caps["appActivity"] = ".launch.LaunchSplashActivity "
            caps["noReset"] = "true"
            caps["deviceName"] = "yf"
            caps["ensureWebviewsHavePages"] = True
            # caps['settings[waitForIdleTimeout]'] = 0
            caps['skipDeviceInitialization'] = "true"
            caps['automationName'] = "uiautomator2"


            self.driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", caps)
            self.driver.implicitly_wait(10)
        else:
            print("driver！=None，复用driver")
            self.driver.launch_app()
        #需要跳转该类下面的goto_main方法中，所以要return self

        return self

    def restart(self):
        # self.driver.close()
        # self.driver.launch_app()
        pass


    def quit(self):
        self.driver.quit()

    def goto_main(self):
        #进入主页，入口方法,完成po页面的切换，需要用到return,
        return MainPage(self.driver)
